extends Sprite2D

@onready var damage_component: DamageComponent = $DamageComponent

var log_scene = preload("res://croptails/scenes/log.tscn")

func _on_hurt_component_hurt(hit_damage : int) -> void:
	damage_component.apply_damage(hit_damage)
	material.set_shader_parameter("shake_intensity", 1.0)
	await get_tree().create_timer(1).timeout
	material.set_shader_parameter("shake_intensity", 0)

func _on_damage_component_max_damage_reached() -> void:
	call_deferred("add_log_scene")
	queue_free()

func add_log_scene() -> void:
	var log_instance = log_scene.instantiate() as Node2D
	log_instance.global_position = global_position
	get_parent().add_child(log_instance)
